<template>
	<view class="login-body">
		<view class="login-body_form">
			<view class="login-body_form_logo">
				<u-image width="300rpx" height="300rpx" src="/static/image/logo/logo_oa_primary.png"></u-image>
			</view>
			<!--      <h1 class="login-body_form_title">欢迎使用</h1>-->
			<h4 class="login-body_form_title_text">小程序演示仿钉钉流程管理</h4>

			<view class="login-body_form_btn_login">
				<u-button type="primary" @click="login">微信授权登录</u-button>
				<!--        <button type="primary" open-type="getPhoneNumber"
		                @getphonenumber="getUserPhoneNumber">点击授权获取手机号
		        </button>-->
			</view>


			<view class="login-body_form_login_account">
				<navigator url="/pages/login/account-login" open-type="redirect">使用账号密码登录</navigator>
			</view>

			<u-modal :show="modelDefault.show" :content="modelDefault.content" :show-cancel-button="true"
				@confirm="modelDefaultConfirm"></u-modal>


<ld-cascader v-model="aaa" :list="list" clearable></ld-cascader>

		</view>
	</view>
</template>

<script>
	import {
		weChatMiAppLogin
	} from "@/api/api-user";

	export default {
		data() {
			return {
				avatarUrl: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
				nickName: '',
				telephone: '',
				countryCode: '86',
				modelDefault: {
					show: false,
					content: '您还未注册，是否去注册',
					openid: ''
				},
				aaa: [],
				list: [{
							"label": "深圳总公司",
							"value": 101,
							"parentId": 100,
							"disabled": false,
							"children": [{
									"label": "研发部门",
									"value": 103,
									"parentId": 101,
									"disabled": false
								},
								{
									"label": "市场部门",
									"value": 104,
									"parentId": 101,
									"disabled": false
								},
								{
									"label": "测试部门",
									"value": 105,
									"parentId": 101,
									"disabled": false,
									"children": [{
										"label": "sdfasfaaaaaa1",
										"value": 111,
										"parentId": 105,
										"disabled": false
									}]
								},
								{
									"label": "财务部门",
									"value": 106,
									"parentId": 101,
									"disabled": false
								},
								{
									"label": "运维部门",
									"value": 107,
									"parentId": 101,
									"disabled": false
								}
							]
						},
						{
							"label": "长沙分公司",
							"value": 102,
							"parentId": 100,
							"disabled": false,
							"children": [{
									"label": "市场部门",
									"value": 108,
									"parentId": 102,
									"disabled": false
								},
								{
									"label": "财务部门",
									"value": 109,
									"parentId": 102,
									"disabled": false
								}
							]
						},
						{
							"label": "fffa",
							"value": 110,
							"parentId": 100,
							"disabled": false
						}
					]
			}
		},
		onLoad: function() {},

		methods: {
			login() {
				let that = this
				uni.login({
					provider: 'weixin', //使用微信登录
					onlyAuthorize: true,
					success: function(loginRes) {
						console.log('loginRes -> ', loginRes)

						weChatMiAppLogin(loginRes.code).then(res => {
							that.$store.dispatch('user/setToken', res.data.token)
							that.$store.dispatch('user/setSessionResult', res.data.sessionResult)

							uni.setStorageSync('foa-user-token', res.data.token);

							setTimeout(function() {
								uni.switchTab({
									url: '/pages/dashboard/index'
								});
							}, 500)
						}).catch(e => {
							if (e.code === 403) {
								that.modelDefault.show = true
								that.modelDefault.openid = e.data.sessionResult.openid
							}
						})
					}
				});
			},
			modelDefaultConfirm() {
				uni.redirectTo({
					url: '/pages/login/register?openid=' + this.modelDefault.openid
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login-body {
		height: 100vh;

		flex: auto;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		.login-body_form {
			width: calc(100% - 5vh);
			height: 70vh;
			overflow: scroll;
		}

		.login-body_form_logo {
			display: block;
			width: 300rpx;
			height: 300rpx;
			margin: 0 auto;
		}

		.login-body_form_title {
			text-align: center;
			color: #2C405A;
			margin-top: 100rpx;
			margin-bottom: 25rpx;
			font-size: 48rpx;
		}

		.login-body_form_title_text {
			text-align: center;
			color: #2C405A;
			margin-top: 25rpx;
			margin-bottom: 140rpx;
		}

		.login-body_form_btn_login {
			margin-bottom: 30rpx;
		}

		.login-body_form_login_account {
			text-align: center;
		}
	}
</style>